package gaml.java.serializer.primitive;

import gaml.error.GamlException;
import gaml.java.ClassSerializer;
import gaml.yaml.ScalarNode;
import gaml.yaml.YamlNode;
import gaml.yaml.ahchor.YamlAnchorCodeStore;
import gaml.yaml.ahchor.YamlAnchorObjectStore;

/**
 * create byte from node
 * create node from byte
 * @author shnireck
 *
 */
public class ByteSerializer implements ClassSerializer<Byte> {

	@Override
	public Class <Byte> getObjectClass () { return Byte.class; }

	@Override
	public boolean noAnchor () { return true; }
	
	@Override
	public Byte restore (YamlNode node, Byte object, YamlAnchorCodeStore anchors) { return Byte.parseByte (node.getValue ().trim ()); }

	@Override
	public YamlNode serialize (YamlNode node, Byte obj, YamlAnchorObjectStore anchors) { return new ScalarNode (node.getParent ()).setValue (obj.toString ()); }

	@Override
	public YamlNode createNode (YamlNode parent) { return new ScalarNode (parent); }

	@Override
	public Byte createObject () throws GamlException { return null; }

}
